package cn.itcast.controller;

import cn.itcast.domain.Courier;
import cn.itcast.domain.Standard;
import cn.itcast.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author： ~Mr·Weng~
 * @CreateTime： 2019年-01月-21日  15:06
 * Look at the wine in the glass toast the rich first.
 */
@Controller
public class CourierController {

    @Autowired
    private CourierService courierService;


    /**
     * 保存
     *
     * @param courier
     * @return
     */
    @RequestMapping("/courier_save")
    public String courier_save(Courier courier) {
        courierService.save(courier);
        return "redirect:/pages/base/courier.html";
    }

    /**
     * 分页查询
     *
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/courier_pageQuery")
    @ResponseBody
    public Map pageQuery( Courier courier , Integer page, Integer rows) {

        Page<Courier> courierResult = null;
        Map<String, Object> map = null;

        if (courier.getCourierNum()!=null && courier.getCourierNum().length()!=0){
            courierResult = courierService.pageQuery(courier, page, rows);
            map = new HashMap<>();
            map.put("page", courierResult.getTotalElements());
            map.put("rows", courierResult.getContent());
        }else{
            System.out.println("courier:"+courier);

            courierResult = courierService.pageQuery(page,rows);

            map = new HashMap<>();
            map.put("page", courierResult.getTotalElements());
            map.put("rows", courierResult.getContent());

        }
        return map;
    }

    @RequestMapping("/courier_delBatch")
    public String deleById(String[] ids, Character i) {
        courierService.deleById(ids, i);
        return "redirect:/pages/base/courier.html";
    }


 /*   @RequestMapping("/courier_search")
    @ResponseBody
    public List<Courier> search(Courier courier) {
        List<Courier> courierList = courierService.search(courier);
        return courierList;
    }*/

}
